#include "drawing.h"

drawing::drawing(void){
}
drawing::~drawing(void){
}

//bresenham algorithmus
void drawing::drawLine(int x0, int y0, int x1, int y1) //Anfangskoordinate und Endkoordinate
{
	Bild *pic=Bild::getInstance();
  int dx = abs(x1-x0), sx = x0<x1 ? 1 : -1;
  int dy = -abs(y1-y0), sy = y0<y1 ? 1 : -1; 
  int err = dx+dy, e2; /* error value e_xy */
 
  for(;;){  /* loop */
	pic->setPixel(x0,y0);
    if (x0==x1 && y0==y1) break;
    e2 = 2*err;
    if (e2 > dy) { err += dy; x0 += sx; } /* e_xy+e_x > 0 */
    if (e2 < dx) { err += dx; y0 += sy; } /* e_xy+e_y < 0 */
  }
}

//bresenham kreis
void drawing::drawCircle(int x0, int y0, int radius) //Anfangskoordinate und Endkoordinate
{
	Bild *pic=Bild::getInstance();
    int f = 1 - radius;
    int ddF_x = 0;
    int ddF_y = -2 * radius;
    int x = 0;
    int y = radius;
 
    pic->setPixel(x0, y0 + radius);
    pic->setPixel(x0, y0 - radius);
    pic->setPixel(x0 + radius, y0);
    pic->setPixel(x0 - radius, y0);
 
    while(x < y) 
    {
      if(f >= 0) 
      {
        y--;
        ddF_y += 2;
        f += ddF_y;
      }
      x++;
      ddF_x += 2;
      f += ddF_x + 1;
 
      pic->setPixel(x0 + x, y0 + y);
      pic->setPixel(x0 - x, y0 + y);
      pic->setPixel(x0 + x, y0 - y);
      pic->setPixel(x0 - x, y0 - y);
      pic->setPixel(x0 + y, y0 + x);
      pic->setPixel(x0 - y, y0 + x);
      pic->setPixel(x0 + y, y0 - x);
      pic->setPixel(x0 - y, y0 - x);
    }
}